package top.goldenyear.porpoise.system.setting.util;

import java.util.List;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import top.goldenyear.porpoise.system.setting.dto.DictItemDto;
import top.goldenyear.porpoise.system.setting.service.IDictItemService;

/**
 * 字典工具类
 *
 * @author Airhead
 */
@Slf4j
public class DictUtils {

  private static final DictItemDto DICT_DATA_NULL = new DictItemDto();
  private static IDictItemService dictItemService;

  public static void init(IDictItemService dictDataApi) {
    DictUtils.dictItemService = dictDataApi;
    log.info("[init][初始化 DictFrameworkUtils 成功]");
  }

  @SneakyThrows
  public static String getDictItemName(String dictCode, String value) {
    DictItemDto dictData = dictItemService.getDictItem(dictCode, value);
    if (dictData != null) {
      return dictData.getName();
    }

    return "";
  }

  @SneakyThrows
  public static String getDictItemValue(String dictCode, String name) {
    DictItemDto dictData = dictItemService.parseDictItem(dictCode, name);
    if (dictData != null) {
      return dictData.getValue();
    }

    return "";
  }

  public static List<DictItemDto> getDictDataList(String dictCode) {
    return dictItemService.getDictItemList(dictCode);
  }
}
